﻿using System;
using System.Linq.Expressions;
using System.Runtime.Serialization;

namespace Emico.Linq.Criterion
{
    [Serializable]
    public class GtExpression<T> : SimpleExpression<T>
        where T : class
    {
        #region Constructors

        public GtExpression(string propertyName, object value)
            : base(propertyName, value)
        {
        }

        protected GtExpression(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
        }

        #endregion

        #region Implement Abstract Method

        public override Expression ToLinqExpression(Criteria<T> criteria, ParameterExpression parameter)
        {
            Type t = typeof(T);
            Expression left = ExpressionHelper.CrateNestExpressionProperty<T>(this.PropertyName, parameter);
            Expression right = Expression.Constant(this.Value, left.Type);
            Expression filter = Expression.GreaterThan(left, right);

            return filter;
        }

        #endregion
    }
}
